﻿namespace SupportSystemUI.Controls.CustomPages.Crew
{
    using System.Windows.Controls;
    using System.Windows.Media;
    using SupportSystemDB;
    using SupportSystemUI.Controls.Pages;

    /// <summary>
    /// Interaction logic for MemberItem.xaml
    /// </summary>
    public partial class MemberItem : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MemberItem"/> class.
        /// </summary>
        /// <param name="member">Member object holding it's data.</param>
        public MemberItem(vMember member)
        {
            this.InitializeComponent();

            this.nameBlock.Text = member.FullName;
            this.positionBlock.Text = member.PositionName;
            this.imageIcon.SetImage(member.LargeImage);

            this.MouseEnter += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
            };
            this.MouseLeave += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Colors.White);
            };
            this.MouseUp += (sender, args) =>
            {
                Global.Instance.PagesScreen.Push(
                    () => new
                    {
                        Member = AppController.Instance.Members.Get(member.Id),
                        Contacts = AppController.Instance.Members.GetContacts(member.Id),
                        Positions = AppController.Instance.Members.ParticipateInEvent(member.Id),
                    },
                    (data) =>
                    {
                        dynamic dData = data as dynamic;
                        return new PageData(
                            new UserProfile(dData.Member, dData.Contacts, dData.Positions),
                            "Member Profile");
                    });
            };
        }
    }
}
